package com.dada;

import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;

/**
 * body进行json序列化
 * */
public class DadaToJson {
	
	//json 序列化使用,本示例使用jackson
    private static ObjectMapper mapper = new ObjectMapper();
	
	public static <T> String toJson(T src) {
        try {
            if (null != mapper) {
                if (src instanceof String) {
                    return (String) src;
                } else {
                    return mapper.writeValueAsString(src);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
